package com.eric.windows.menu;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.PopupMenu;
import android.widget.TextView;

import com.eric.windows.R;

/**
 * 弹出菜单
 */
public class PopUpMenuTestActivity extends AppCompatActivity {
    private TextView txt_menu;
    private PopupMenu popupMenu;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu_test);
        txt_menu = (TextView) findViewById(R.id.txt_menu);
        txt_menu.setText("菜单测试");

        popupMenu = new PopupMenu(PopUpMenuTestActivity.this,txt_menu);
        getMenuInflater().inflate(R.menu.popup_menu,popupMenu.getMenu());
//        popupMenu.inflate(R.menu.popup_menu);
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()){
                    case R.id.fount_10:
                        txt_menu.setTextSize(10*2);
                        break;
                    case R.id.fount_12:
                        txt_menu.setTextSize(12*2);
                        break;
                    case R.id.fount_14:
                        txt_menu.setTextSize(14*2);
                        break;
                    case R.id.fount_16:
                        txt_menu.setTextSize(16*2);
                        break;
                    case R.id.fount_18:
                        txt_menu.setTextSize(18*2);
                        break;
                }
                return true;
            }
        });


        txt_menu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupMenu.show();
            }
        });

    }
}
